fix(cp): return non-nil Content from dry-run CopyFromContainer - #13982
Open
glours wants to merge 1 commit into
Open
fix(cp): return non-nil Content from dry-run CopyFromContainer#13982glours wants to merge 1 commit into
glours wants to merge 1 commit into
Conversation
The caller in pkg/compose/cp.go unconditionally defers res.Content.Close() once the call succeeds. The dry-run client returned a zero-value result with a nil Content reader, so `docker compose cp --dry-run <ctr>:<path> <dst>` panicked with a nil pointer dereference. Return an empty NopCloser instead, matching the pattern already used for the other stream results in this file. Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟡 NEEDS ATTENTION
One medium-severity confirmed finding: the PR correctly fixes the nil-pointer panic by returning a non-nil Content, but the Stat field in the returned CopyFromContainerResult remains zero-valued. Since ContainerStatPath is already called (and its result discarded), the fix is straightforward: capture and return the Stat so the caller's res.Stat.Mode.IsDir() check works correctly for directory sources in dry-run mode.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
maxproske
reviewed
Jul 30, 2026
maxproske
left a comment
Contributor
There was a problem hiding this comment.
Non-binding LGTM
cat > compose.yaml <<'EOF'
services:
app:
image: alpine
EOF
./bin/build/docker-compose create
./bin/build/docker-compose cp --dry-run app:/ .
# no-op instead of panic :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I did
The caller in
pkg/compose/cp.gounconditionally defersres.Content.Close()once the call succeeds. The dry-run client returned a zero-value result with a nilContentreader, sodocker compose cp --dry-run <ctr>:<path> <dst>panicked with a nil pointer dereference. Return an emptyNopCloserinstead, matching the pattern already used for the other stream results in this file.Related issue
https://docker.atlassian.net/browse/DDB-589
(not mandatory) A picture of a cute animal, if possible in relation to what you did
